package me.gavin.util

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import me.gavin.di.instanceHolder

inline fun <reified T> String.fromJson(gson: Gson = instanceHolder.get()) =
    try {
        gson.fromJson<T>(this, object : TypeToken<T>() {}.type)
    } catch (e: Exception) {
        null
    }

fun Any.toJson(gson: Gson = instanceHolder.get()): String = gson.toJson(this)